SUBDIRS = . test

lib_LTLIBRARIES = libgnc-core-utils.la

libgnc_core_utils_la_SOURCES = \
  binreloc.c \
  gnc-filepath-utils.c \
  gnc-gconf-utils.c \
  gnc-gdate-utils.c \
  gnc-gkeyfile-utils.c \
  gnc-glib-utils.c \
  gnc-jalali.c \
  gnc-locale-utils.c \
  gnc-main.c \
  gnc-path.c \
  gnc-uri-utils.c \
  swig-core-utils.c

libgnc_core_utils_la_LIBADD = \
  ${GUILE_LIBS} \
  ${GLIB_LIBS} \
  ${BINRELOC_LIBS} \
  ${GTK_MAC_LIBS} \
  ${GCONF_LIBS} \
  ${QOF_LIBS}

noinst_HEADERS = \
  binreloc.h \
  gnc-main.h \
  gnc-filepath-utils.h \
  gnc-gconf-utils.h \
  gnc-gdate-utils.h \
  gnc-gkeyfile-utils.h \
  gnc-glib-utils.h \
  gnc-jalali.h \
  gnc-locale-utils.h \
  gnc-path.h \
  gnc-uri-utils.h

if BUILDING_FROM_SVN
swig-core-utils.c: core-utils.i ${top_srcdir}/src/base-typemaps.i
	$(SWIG) -guile $(SWIG_ARGS) -Linkage module \
	-I${top_srcdir}/src -o $@ $<
endif

AM_CPPFLAGS = \
  ${GUILE_INCS} \
  ${GLIB_CFLAGS} \
  ${GCONF_CFLAGS} \
  ${GTK_MAC_CFLAGS} \
  ${QOF_CFLAGS} \
  -I${top_srcdir}/src/libqof/qof \
  -I${top_builddir}/src \
  -I${top_srcdir}/src

gncmoddir = ${GNC_SHAREDIR}/guile-modules/gnucash
gncmod_DATA = core-utils.scm

if GNUCASH_SEPARATE_BUILDDIR
#Only needed when srcdir and builddir are different
#for running
SCM_FILE_LINKS = ${gncmod_DATA}
endif

.scm-links: 
	$(RM) -rf gnucash
	mkdir -p  gnucash
if GNUCASH_SEPARATE_BUILDDIR
	for X in ${SCM_FILE_LINKS} ; do \
	  $(LN_S) -f ${srcdir}/$$X . ; \
	done
endif
	( cd gnucash; for A in $(gncmod_DATA) ; do $(LN_S) -f ../$$A . ; done )
if ! OS_WIN32
# Windows knows no "ln -s" but uses "cp": must copy every time (see bug #566567).
	touch .scm-links
endif

noinst_DATA = .scm-links
BUILT_SOURCES = gncla-dir.h gnc-version.h
EXTRA_DIST = $(gncmod_DATA) core-utils.i gncla-dir.h.in gnc-svninfo.h
clean-local:
	rm -rf gnucash

CLEANFILES = $(BUILT_SOURCES) .scm-links
MAINTAINERCLEANFILES = swig-core-utils.c

AM_CPPFLAGS += -DG_LOG_DOMAIN=\"gnc.core-utils\"

gncla-dir.h: gncla-dir.h.in ${top_builddir}/config.status Makefile
	rm -f $@.tmp
	sed < $< > $@.tmp \
		-e 's#@-DATADIRNAME-@#${DATADIRNAME}#g' \
		-e 's#@-libdir-@#${libdir}#g' \
		-e 's#@-bindir-@#${bindir}#g' \
		-e 's#@-sysconfdir-@#${sysconfdir}#g' \
		-e 's#@-datadir-@#${datadir}#g' \
		-e 's#@-prefix-@#${prefix}#g'
	mv $@.tmp $@

## We borrow guile's convention and use @-...-@ as the substitution
## brackets here, instead of the usual @...@.  This prevents autoconf
## from substituting the values directly into the left-hand sides of
## the sed substitutions.
gnc-version.h: _gnc-version.h
	-if [ ! -f gnc-version.h ]; then cp _gnc-version.h gnc-version.h; fi
	-cmp -s _gnc-version.h gnc-version.h || cp _gnc-version.h gnc-version.h
	-rm -f _gnc-version.h

_gnc-version.h: gnc-svninfo.h Makefile
	@echo "/* Autogenerated. Do not change. */"	 > _gnc-version.h
	@echo "#ifndef GNC_VERSION_H"			>> _gnc-version.h
	@echo "#define GNC_VERSION_H"			>> _gnc-version.h
	@echo ""					>> _gnc-version.h
	@svninfo=`${top_srcdir}/util/gnc-svnversion ${top_srcdir}` ; \
	if [ $$? = 0 ] ; then \
		echo "#define GNUCASH_SVN 1"		>> _gnc-version.h ; \
	fi
	@echo "#define GNUCASH_BUILD_DATE \"`date +%Y-%m-%d`\"" >> _gnc-version.h
	@echo "#include \"gnc-svninfo.h\""		>> _gnc-version.h
	@echo "#endif"					>> _gnc-version.h

gnc-svninfo.h: _gnc-svninfo.h
	-if [ ! -f gnc-svninfo.h ]; then cp _gnc-svninfo.h gnc-svninfo.h; fi
	-cmp -s _gnc-svninfo.h gnc-svninfo.h || cp _gnc-svninfo.h gnc-svninfo.h
	-rm -f _gnc-svninfo.h

_gnc-svninfo.h: Makefile
	@svninfo=`${top_srcdir}/util/gnc-svnversion ${top_srcdir}` ; \
	if [ $$? = 0 ] ; then \
		if [ -z "$$svninfo" ] ; then \
			echo "gnc-svnversion failed.  figure out why." ; \
			echo "can't determine svn revision from ${top_srcdir}." ; \
			exit 1 ; \
		fi ; \
		echo "/* Autogenerated. Do not change. */" > _gnc-svninfo.h ; \
		echo "#define GNUCASH_SVN_REV \"$$svninfo\"" >> _gnc-svninfo.h ; \
	else \
		if [ -r $(srcdir)/gnc-svninfo.h ] ; then \
			cp $(srcdir)/gnc-svninfo.h _gnc-svninfo.h ; \
		else \
			echo "You're building from SVN...  But your build system is broken" ; \
			echo "Don't do that.   Complain to your build-system creator." ; \
			exit 1 ; \
		fi ; \
	fi
